<?php

namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class HomesysController extends AdminbaseController {
    public function index() {
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        $queryDesc='order by id';
        
        $postData=array();
        $where='';
        $postData['p']=$p;

        if (isset($_POST['name']) && !empty($_POST['name'])){
            $postData['name']=addslashes(trim($_POST['name']));
            $where=' where name like "%'.$postData['name'].'%" ';
        }
        
        $Model = M();
        $query=$Model->query("SELECT count(id) as count FROM `qdui` ".$where."  ");
        $count=$query[0]['count'];
        $page = $this->page($count, 10, $p);
        $uInfo=$Model->query("SELECT * FROM `qdui` ".$where."  ".$queryDesc." limit ".(($p-1)*10).",10 ");
        $theData=array();
        include '/var/www/chongya/web/thearray.php';
        foreach ($uInfo as $v){
            $getDui=$Model->query("SELECT name,phone FROM `uinfo` where openid='".$v['openid']."' limit 0,1 ");
            $getDuiName=$getDui[0]['name'];
            $getDuiPhone=$getDui[0]['phone']; 
            $theData[]=array('id'=>$v['id'],'name'=>$v['name'],'qtype'=> $qiuType[$v['qtype']] ,
                'dname'=>$getDuiName,'dphone'=>$getDuiPhone,
                'diqu'=>$v['shengname'].$v['shiname'].$v['quname'],'createtime'=>$v['createtime']
            );
        }
        $this->assign("postData", $postData);
        $this->assign("page", $page->show('Admin'));
        $this->assign("thedata", $theData);

        $this->display();
    }
    
    public function list() {
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        if (isset($_GET['id'])){
            $id=$_GET['id'];
        }else{
            exit;
        }
        $Model = M();
        $qDui=$Model->query("SELECT * FROM `qdui`  where id='".$id."' limit 0,1 ");
        $qduiName=$qDui[0]['name'];
        $theData=array();
        //队长
        include '/var/www/chongya/web/thearray.php';
        $getU=$Model->query("SELECT * FROM `uinfo` where openid='".$qDui[0]['openid']."' limit 0,1 ");
        $theData[]=array('id'=>$getU[0]['id'],
            'zubie'=>getZuByAge($getU[0]['age']),
            'name'=>$getU[0]['name'],
            'qiuhao'=>99,
            'gao'=>$getU[0]['gao'],
            'weight'=>$getU[0]['weight'],
            'weizhi'=>'',
            'idcard'=>$getU[0]['idcard'],
            'phone'=>$getU[0]['phone'],
            'shenpi'=>'队长',
            'createtime'=>$v['createtime']
        );
        

        $postData=array();
        $postData['p']=$p;
        
        $uInfo=$Model->query("SELECT * FROM `joinqiu` where qiuid='".$id."'   ");
      
        
        foreach ($uInfo as $v){
            $getU=$Model->query("SELECT * FROM `uinfo` where openid='".$v['openid']."' limit 0,1 ");
           
            $shenpi='未审批';
            if(1 == $v['isapply']){
                $shenpi='已审批';
            }
            if(2 == $v['isapply']){
                $shenpi='未同意';
            }
            $getzubie=$getU[0]['zubie'];
            if (isset($zuBie[$getU[0]['zubie']])){
                $getzubie=$zuBie[$getU[0]['zubie']];
            }
            $theData[]=array('id'=>$getU[0]['id'],
                'zubie'=>$getzubie,
                'name'=>$getU[0]['name'],
                'qiuhao'=>$v['qiuhao'],
                'gao'=>$getU[0]['gao'],
                'weight'=>$getU[0]['weight'],
                'weizhi'=>$weizhiList[$v['weizhi']],
                'idcard'=>$getU[0]['idcard'],
                'phone'=>$getU[0]['phone'],
                'shenpi'=>$shenpi,
                'createtime'=>$v['createtime']
            );
        }
        
        
        
        $this->assign("qduiName", $qduiName);
        $this->assign("postData", $postData);
        $this->assign("thedata", $theData);
        
        $this->display();
    }
    
    
  
    public function edit() {
        if (isset($_GET['id'])){
            $id=$_GET['id'];
        }else{
            exit;
        }
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        $Model = M();
        $dataInfo=$Model->query("SELECT * FROM `zhi_supplier` where id='".$id."' limit 0,1  ");
        $this->assign("p", $p);
        $this->assign("dataInfo", $dataInfo[0]);
         
        $this->display();
    }
    
    public function add() {
         
        
        $this->display();
    }
    
    public function add_post() {
        if (isset($_POST['title']) && !empty($_POST['title'])){
            $Model = M("supplier", 'zhi_');
            $data=array();
            $data['title'] = addslashes(trim($_POST['title']));
            $data['subtitle'] = addslashes(trim($_POST['subtitle']));
            $data['workyear'] = addslashes(trim($_POST['workyear']));
            $data['sanchang'] = addslashes(trim($_POST['sanchang']));
            $data['jieshao'] = addslashes(trim($_POST['jieshao']));
            $data['lvli'] = addslashes(trim($_POST['lvli']));
            $data['skill_type'] = addslashes(trim($_POST['skill_type']));
            
            
            $data['photo'] = $_POST['smeta']['thumb'];
            $data['star'] = addslashes(trim($_POST['star']));
            $data['price'] = addslashes(trim($_POST['price']));
            $data['paixu'] = addslashes(trim($_POST['paixu']));
            $data['createtime'] = date("Y-m-d H:i:s");
            
            $Model->add($data);
            $info=json_encode(array('status'=>'success'));
            echo $info;
        }
    }
     
    public function editpost() {
 
        if (isset($_POST['title']) && isset($_POST['option_id'])){
            $Model = M("supplier", 'zhi_');
             
            $data=array();
            $data['title'] = addslashes(trim($_POST['title']));
            $data['subtitle'] = addslashes(trim($_POST['subtitle']));
            $data['workyear'] = addslashes(trim($_POST['workyear']));
            $data['sanchang'] = addslashes(trim($_POST['sanchang']));
            $data['jieshao'] = addslashes(trim($_POST['jieshao']));
            $data['lvli'] = addslashes(trim($_POST['lvli']));
            $data['photo'] = $_POST['photo'];
            $data['skill_type'] = addslashes(trim($_POST['skill_type']));
            $data['star'] = addslashes(trim($_POST['star']));
            $data['price'] = addslashes(trim($_POST['price']));
            $data['paixu'] = addslashes(trim($_POST['paixu']));
            $data['createtime'] = date("Y-m-d H:i:s");
            $id=$_POST['option_id'];
            $Model->where('id='.$id)->save($data);
            
            $info=json_encode(array('status'=>'yes'));
            echo $info;
        }
    }
 
}
